﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AirlineBooking.Models.DTO
{
    public class DTOClassType
    {
        
            static DTOClassType()
            {
                using (AirLineDBModelEntities db = new AirLineDBModelEntities())
                {
                    AirlineBooking.ClassType t = db.ClassTypes.FirstOrDefault(i => i.Name == "Business");
                    Business = t != null ? new DTOClassType(t) : null;
                    t = db.ClassTypes.FirstOrDefault(i => i.Name == "First Class");
                    FirstClass = t != null ? new DTOClassType(t) : null;
                    t = db.ClassTypes.FirstOrDefault(i => i.Name == "Economic");
                    Economic = t != null ? new DTOClassType(t) : null;
                    AllTypes = new DTOClassType[] { Economic, Business, FirstClass };
                }
            }

            private DTOClassType(int id, string value)
            {
                Id = id;
                Value = value;
            }

            private DTOClassType(AirlineBooking.ClassType item)
                : this(item.Id, item.Name)
            {
            }
            public string Value { get; set; }
            public int Id { get; set; }
            public static readonly DTOClassType Business;
            public static readonly DTOClassType FirstClass;
            public static readonly DTOClassType Economic;
            public static readonly DTOClassType[] AllTypes;
    }
}